// 属性访问器

class Emp {
  var ename;
  num _eage = 0;

  num get eage {
    print("访问eage属性的值");
    return _eage;
  }

  set eage(num value) {
    if (value >= 17 && value <= 60) {
      this._eage = value;
    } else {
      throw Exception("年龄超出范围，必须介于18~60岁之间");
    }
  }

  Emp(ename, eage) {
    this.ename = ename;
    this.eage = eage;
  }

  @override
  String toString() {
    return "Emp { ename: $ename, eage: $eage }";
  }
}

// 入口主函数
void main() {
  try {
    var eric = Emp("Eric Evans", 18);
    print(eric);
  } catch(e) {
    print(e);
  }
}
